package com.yuhs.zixing.study.spring.boot.mybatis.dao.generator;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName MybatisGenerator
 * @Description 代码生成
 * @Author yuhs
 * @CreateDate 2020/11/20
 **/
public class MybatisGenerator {
    public static void main(String[] args) {
        try {

            List<String> warningList = new ArrayList<>();
            ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
            InputStream resourceAsStream = contextClassLoader.getResourceAsStream("generatorConfig.xml");
            ConfigurationParser configurationParser = new ConfigurationParser(warningList);
            Configuration configuration = configurationParser.parseConfiguration(resourceAsStream);

            DefaultShellCallback defaultShellCallback = new DefaultShellCallback(true);
            MyBatisGenerator myBatisGenerator = new MyBatisGenerator(configuration, defaultShellCallback, warningList);
            myBatisGenerator.generate(null);
            warningList.forEach(System.out::println);

        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
